<?php

class Validator {
    
    private $errors = array();
    
    public function addError($field, $mess){
        $this->errors[$field][] = $mess;
    }
    
    public function getErrors(){
        return $this->errors;
    }
    
    public function isValid(){
        return ( count($this->errors) === 0 );
    }
    
    public function notBlank($field, $val){
        if ( ! $val ){
            $this->errors[$field][] = 'This value is required.';
            return false;
        }
        return true;
    }
    
    public function email($field, $val){
        if ( ! filter_var($val, FILTER_VALIDATE_EMAIL) ){
            $this->errors[$field][] = 'This value is not correct email format.';
            return false;
        }
        return true;
    }
    
}
